﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdateStudentData.aspx.cs"
    Inherits="Corsat.Web._2013.Administration.UpdateStudentData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">
<head>
    <title></title>
    <style type="text/css">
        .progressBackgroundFilter
        {
            position: fixed;
            top: 0px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            overflow: hidden;
            padding: 0;
            margin-left: auto;
            margin-right: auto;
            background-color: #000;
            filter: alpha(opacity=50);
            opacity: 0.5;
            z-index: 1000;
        }
        
        .processMessage
        {
            margin-left: auto;
            margin-right: auto;
            position: fixed;
            top: 30%;
            left: 43%;
            padding: 10px;
            width: 14%;
            z-index: 1001;
            background-color: #fff;
            border: solid 1px #000;
            text-align: center;
            font-size: large;
            font-style: oblique;
        }
        
        .rdoBtn label
        {
            display: inline-block;
        }
    </style>
    <link href="../libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.10.0.min.js" type="text/javascript"></script>
    <script src="../libs/bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <script type="text/javascript">
        function getAccountData() {
            if (!$('#txtSearch').val()) {
                alert('لابد من ادخال الرقم');
                return;
            }

            $.ajax({
                type: "POST",
                url: "UpdateStudentData.aspx/GetData",
                data: '{"searchText":' + $('#txtSearch').val() + ' }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d.error && msg.d.error == 'notfound') {
                        alert('لا يوجد بيانات لهذا الرقم');
                    }
                    $("#txtArabicName").val(msg.d.ArabicName);
                    $("#txtCorsatId").val(msg.d.CorsatId);
                    $("#txtEmail").val(msg.d.Email);
                    $("#txtSSN").val(msg.d.SSN);
                    $("#hdnAccountId").val(msg.d.AccountId);

                    if (msg.d.Telephones) {          
                        if (msg.d.Telephones.length > 0) {

                            $("#ddlTelephone1").val(msg.d.Telephones[0].Type.Id);
                            $("#txtTelephone1").val(msg.d.Telephones[0].Number);
                        }

                        if (msg.d.Telephones.length > 1) {

                            $("#ddlTelephone2").val(msg.d.Telephones[1].Type.Id);
                            $("#txtTelephone2").val(msg.d.Telephones[1].Number);
                        }

                        if (msg.d.Telephones.length == 3) {

                            $("#ddlTelephone3").val(msg.d.Telephones[2].Type.Id);
                            $("#txtTelephone3").val(msg.d.Telephones[2].Number);
                        }
                    }


                    //$('#ddlLevel').val(msg.d.QuestionLevelId);
                    //data = $.parseJSON(data);

                    //                    $.each(msg.d.Answers, function (i, item) {
                    //                        var html = '<div class="answerClass"> <input type="checkbox" style="margin-left:30px" checked="checked"> <input type="text" name="answer_' +
                    //                            item.AnswerText + '" id="answer_' + item.AnswerId + '" value="' + item.AnswerText + '" style="width: 82%" >' +
                    //                ' <a type="button" onclick="removeAnswers(this);" style="color: white;margin-bottom:9px" class="icon-remove" text="save" id="Button1"></a></div>';
                    //                        if (!item.IsRightAnswer) {
                    //                            html = html.replace('checked="checked"', "");
                    //                        }
                    //                        $("#txtAnswers").append(html);
                    //                    });
                }
            });
        }
        function saveAccount() {
            if (!$("#txtArabicName").val()) {
                alert('لابد من إدخال الأسم');
                return;
            }
            if (!$("#txtSSN").val()) {
                alert('لابد من اختيار الرقم القومي');
                return;
            }
            if (!$("#hdnAccountId").val()) {
                alert('لابد من ادخال بيان للتعديل');
                return;
            }

            if (confirm("تأكيد التعديل البيانات")) {
                var allTele = [];
                if ($("#ddlTelephone1").val() && $("#txtTelephone1").val()) {
                    var tempTele = {
                        "Number": $("#txtTelephone1").val(),
                        "Type": { "Id": $("#ddlTelephone1").val() }
                    };
                    allTele.push(tempTele);
                }
                if ($("#ddlTelephone2").val() && $("#txtTelephone2").val()) {
                    var tempTele = {
                        "Number": $("#txtTelephone2").val(),
                        "Type": { "Id": $("#ddlTelephone2").val() }
                    };
                    allTele.push(tempTele);
                }
                if ($("#ddlTelephone3").val() && $("#txtTelephone3").val()) {
                    var tempTele = {
                        "Number": $("#txtTelephone3").val(),
                        "Type": { "Id": $("#ddlTelephone3").val() }
                    };
                    allTele.push(tempTele);
                }

                var account = {
                    "AccountId": $("#hdnAccountId").val(),
                    "Email": $('#txtEmail').val(),
                    "ArabicName": $("#txtArabicName").val(),
                    "SSN": $("#txtSSN").val(),
                    "Telephones": allTele
                };

                $.ajax({
                    type: "POST",
                    url: "UpdateStudentData.aspx/Save",
                    data: JSON.stringify({ account: account }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        if (msg.d) {
                            alert('تم الحفظ بنجاح');
                            getAccountData();
                        } else {
                            alert('حدث خطأ ما , لم يتم الحفظ');
                        }
                        return;
                    }
                });
            }
        }
    </script>
</head>
<body>
    <form runat="server">
    <div class="hero-unit">
        <h1>
            تعديل البيانات</h1>
        <p>
            <span>الرقم القومي</span>
            <input id="txtSearch" width="100%" style="text-align: center;"></input>
            <a class="btn btn-primary btn-large" onclick="getAccountData()">بحث</a>
            <input type="hidden" id="hdnAccountId"></input>
        </p>
        <br />
        <table style="font-size: large; font-weight: bold;">
            <tr>
                <td style="width: 30%">
                    <span>الإسم</span>
                </td>
                <td>
                    <input id="txtArabicName" width="100%" style="text-align: center;"></input>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                </td>
            </tr>
            <tr>
                <td style="width: 30%">
                    <span>الرقم الكورساتى</span>
                </td>
                <td>
                    <input id="txtCorsatId" readonly="true" width="30%" style="text-align: center;"></input>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                </td>
            </tr>
            <tr>
                <td style="width: 30%">
                    <span>الرقم القومى</span>
                </td>
                <td>
                    <input id="txtSSN" width="100%" style="text-align: center;"></input>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                </td>
            </tr>
            <tr>
                <td style="width: 30%">
                    <span>البريد الإلكترونى</span>
                </td>
                <td>
                    <input id="txtEmail" width="100%" style="text-align: center;"></input>
                </td>
            </tr>
            <tr>
                <td style="width: 30%">
                    <span>أرقام التليفونات</span>
                </td>
                <td>
                    <table>
                        <tr>
                            <td>
                                <input id="txtTelephone1" style="text-align: center;"></input>
                            </td>
                            <td>
                                <asp:DropDownList runat="server" ID="ddlTelephone1"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="txtTelephone2" style="text-align: center;"></input>
                            </td>
                            <td>
                                <asp:DropDownList runat="server" ID="ddlTelephone2"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="txtTelephone3" style="text-align: center;"></input>
                            </td>
                            <td>
                                <asp:DropDownList runat="server" ID="ddlTelephone3"/>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                </td>
            </tr>
        </table>
        <p>
            <a class="btn btn-primary btn-large" onclick="saveAccount()">حفظ</a></p>
    </div>
    </form>
    <br />
</body>
</html>
